package com.ia.aistream.manager.system.impl;

import com.ia.aistream.common.utils.StringUtils;
import com.ia.aistream.manager.system.ISysRoleManager;
import com.ia.aistream.mapper.system.SysRoleMapper;
import com.ia.aistream.model.system.entity.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Component
public class SysRoleManagerImpl implements ISysRoleManager {

    @Autowired(required = false)
    private SysRoleMapper roleMapper;

    @Override
    public Set<String> selectRoleKeys(Long userId) {
        List<SysRole> perms = roleMapper.selectRolesByUserId(userId);
        Set<String> permsSet = new HashSet<>();
        for (SysRole perm : perms)
        {
            if (StringUtils.isNotNull(perm))
            {
                permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
            }
        }
        return permsSet;
    }
}
